package com.ctg.payroll2.action.workflow;

import java.sql.SQLException;
import java.util.List;

import com.ctg.payroll2.action.BaseAction;
import com.ctg.payroll2.bean.ComboData;
import com.ctg.payroll2.bean.filter.WorkflowAccountFilter;
import com.ctg.payroll2.bean.po.workflow.FlowUser;
import com.ctg.payroll2.service.workflow.WorkflowAccountService;
import com.ctg.payroll2.util.Constants;
import com.ctg.platform.core.security.Exception.SecurityException;
import com.ctg.platform.util.Page;
import com.ctg.platform.util.Parse;

public class WorkflowAccountAction extends BaseAction {
	private static final long serialVersionUID = -4383047290245089481L;
	/**
	 * 查询调价过滤类
	 */
	private WorkflowAccountFilter filter;

	private FlowUser flowUser;
	/**
	 * 组织结构下拉框
	 */
	private List<ComboData> orgComb;
	/**
	 * 翻页结果
	 */
	private Page result;
	/**
	 * 注入的service
	 */
	private WorkflowAccountService service;

	/**
	 * @param service
	 *            设置service
	 */
	public void setService(WorkflowAccountService service) {
		this.service = service;
	}

	@Override
	protected void commonOperations() {
		try {
			orgComb = service.queryFlowOrgchartComb();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void createEntity() {
		try {
			service.insertFlowUser(flowUser, currentUser);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void deleteEntity() {
		try {
//			System.out.println(filter.getIds());
			service.deleteFlowUserByIds(filter.getIds(),currentUser);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void exportXLS() {

	}

	@Override
	protected void queryEntity() {
		if (filter == null)
			filter = new WorkflowAccountFilter();
		filter.setStartIndex(Parse.toInteger(request
				.getParameter(Constants.START), 0));
		filter.setEndIndex(Parse.toInteger(request
				.getParameter(Constants.LIMIT), Constants.DEFAULT_PAGE_SIZE));
		try {
			result = service.queryFlowUserByFilter(filter);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	protected void retrieveEntity() {

	}

	@Override
	protected void updateEntity() {
		try {
			service.updateFlowUser(flowUser);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * @return 返回filter
	 */
	public WorkflowAccountFilter getFilter() {
		return filter;
	}

	/**
	 * @param filter
	 *            设置filter
	 */
	public void setFilter(WorkflowAccountFilter filter) {
		this.filter = filter;
	}

	/**
	 * @return 返回result
	 */
	public Page getResult() {
		return result;
	}

	/**
	 * @param result
	 *            设置result
	 */
	public void setResult(Page result) {
		this.result = result;
	}

	/**
	 * @return 返回orgComb
	 */
	public List<ComboData> getOrgComb() {
		return orgComb;
	}

	/**
	 * @param orgComb
	 *            设置orgComb
	 */
	public void setOrgComb(List<ComboData> orgComb) {
		this.orgComb = orgComb;
	}

	public FlowUser getFlowUser() {
		return flowUser;
	}

	public void setFlowUser(FlowUser flowUser) {
		this.flowUser = flowUser;
	}

}
